package com.yunfeisoft.business.dao.impl.postgres;

import com.applet.base.ServiceDaoImpl;
import com.applet.sql.builder.WhereBuilder;
import com.applet.utils.Page;
import com.yunfeisoft.business.dao.inter.PmsProductAttributeValueDao;
import com.yunfeisoft.business.model.PmsProductAttributeValue;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * ClassName: PmsProductAttributeValueDaoImpl
 * Description: 商品属性值表Dao实现
 * Author: Jackie liu
 * Date: 2020-06-02
 */
@Repository
public class PmsProductAttributeValueDaoImpl extends ServiceDaoImpl<PmsProductAttributeValue, String> implements PmsProductAttributeValueDao {

    @Override
    public Page<PmsProductAttributeValue> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        if (params != null) {
            initPageParam(wb, params);
        }
        return queryPage(wb);
    }

    @Override
    public int deleteByProductId(String productId) {
        if (StringUtils.isBlank(productId)) {
            return 0;
        }

        WhereBuilder wb = new WhereBuilder();
        wb.andEquals("productId", productId);
        return deleteByCondition(wb);
    }

    @Override
    public List<PmsProductAttributeValue> queryByProductId(String productId) {
        if (StringUtils.isBlank(productId)) {
            return new ArrayList<>();
        }

        WhereBuilder wb = new WhereBuilder();
        wb.andEquals("productId", productId);
        return query(wb);
    }
}